package co.yixiang.yshop.module.member.dal.mysql.integralrule;

import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
import co.yixiang.yshop.module.member.controller.admin.integralrule.vo.IntegralRuleExportReqVO;
import co.yixiang.yshop.module.member.controller.admin.integralrule.vo.IntegralRulePageReqVO;
import co.yixiang.yshop.module.member.dal.dataobject.integralrule.IntegralRuleDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 会员积分规则 Mapper
 *
 * @author admin
 */
@Mapper
public interface IntegralRuleMapper extends BaseMapperX<IntegralRuleDO> {

    default PageResult<IntegralRuleDO> selectPage(IntegralRulePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IntegralRuleDO>()
                .eqIfPresent(IntegralRuleDO::getType, reqVO.getType())
                .likeIfPresent(IntegralRuleDO::getTypeName, reqVO.getTypeName())
                .eqIfPresent(IntegralRuleDO::getIntegral, reqVO.getIntegral())
                .eqIfPresent(IntegralRuleDO::getAttribute1, reqVO.getAttribute1())
                .eqIfPresent(IntegralRuleDO::getEnable, reqVO.getEnable())
                .betweenIfPresent(IntegralRuleDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(IntegralRuleDO::getId));
    }

    default List<IntegralRuleDO> selectList(IntegralRuleExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<IntegralRuleDO>()
                .eqIfPresent(IntegralRuleDO::getType, reqVO.getType())
                .likeIfPresent(IntegralRuleDO::getTypeName, reqVO.getTypeName())
                .eqIfPresent(IntegralRuleDO::getIntegral, reqVO.getIntegral())
                .eqIfPresent(IntegralRuleDO::getAttribute1, reqVO.getAttribute1())
                .eqIfPresent(IntegralRuleDO::getEnable, reqVO.getEnable())
                .betweenIfPresent(IntegralRuleDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(IntegralRuleDO::getId));
    }

    @Delete("delete from yshop_integral_rule")
    void delete();
}
